package flatlandRPG;

import org.lwjgl.input.Keyboard;
import java.util.LinkedList;

// -------------------------------------------------------------------------
/**
 * Manages collisions between movable objects and solid objects. If an object
 * implements both IMoveable and ISolid, you will have to add it twice, casting
 * it to each type.
 *
 * @author evant
 * @version Apr 17, 2011
 */
public class ActorManager
    implements ILogic, IDrawable
{
    private LinkedList<Actor> actors;
    private Player            player;


    // ----------------------------------------------------------
    /**
     * Create a new ActorManager object.
     *
     * @param player
     *            the player that the actors converse with
     */
    public ActorManager(Player player)
    {
        actors = new LinkedList<Actor>();
        this.player = player;
    }


    // ----------------------------------------------------------
    /**
     * Adds an actor object to the actor manager.
     *
     * @param actor
     *            the actor
     */
    public void add(Actor actor)
    {
        actors.add(actor);
    }


    /**
     * When the player is close enough to the actor and uses the 'use' key, he
     * talks to the actor.
     */
    public void doLogic()
    {
        for (Actor actor : actors)
        {
            if (TestableKeyboard.isKeyDown(Keyboard.KEY_E)
                && !actor.isConversing())
            {
                actor.talk(player.getLocation());
            }
            actor.doLogic();
        }
    }


    @Override
    public void draw()
    {
        for (Actor actor : actors)
        {
            actor.draw();
        }
    }
}
